package com.leyou.goods.controller;

import com.leyou.goods.service.GoodsHtmlService;
import com.leyou.goods.service.GoodsService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("item")
public class GoodsWebController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private GoodsHtmlService goodsHtmlService;

    @Autowired
    private AmqpTemplate amqpTemplate;


    @GetMapping("{spuId}.html")
    public String queryGoodsBySpuId(@PathVariable("spuId")Long spuId, Model model){
        //加载所需要的数据
        Map<String, Object> map = goodsService.loadData(spuId);
        //把数据存入数据模型
        model.addAllAttributes(map);
        //页面静态化
        goodsHtmlService.asyncExecute(spuId);

        return "item";
    }


}
